package com.medical.controller;

import com.github.pagehelper.PageInfo;
import com.medical.entity.SysMbzc;
import com.medical.service.MbzcService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/mbzc")
public class MbzcController extends BaseControllelr<SysMbzc>{
    @Autowired
    private MbzcService mbzcService;

    /**
     * 获取用户信息列表
     * @param model
     * @return
     */
    @RequestMapping("/getMbzcList")
    public String getMbzcList(Integer currentPage, Integer limit, HttpServletRequest request, Model model) {
        String mbzcName = request.getParameter("context");
        currentPage = currentPage != null ? currentPage : 1;
        limit = limit != null ? limit : 10;

        PageInfo<SysMbzc> pageInfo = mbzcService.getMbzcList(mbzcName, currentPage, limit);

        model.addAttribute("pageInfo", pageInfo);
        model.addAttribute("context", mbzcName);

        return "/mbzc/mbzc_list";
    }

    /**
     * 打开添加页面
     * @param model
     * @return
     */
    @RequestMapping("/openAdd")
    public String openAdd(Model model) {
        return "/mbzc/mbzc_add";
    }

    /**
     * 添加用户信息
     * @param sysMbzc
     * @param model
     * @return
     */
    @RequestMapping("/add")
    public String add(SysMbzc sysMbzc, HttpServletRequest request, Model model) {
        mbzcService.addMbzc(sysMbzc);
        return getMbzcList(1, 10, request, model);
    }

    /**
     * 打开编辑页面
     * @param model
     * @return
     */
    @RequestMapping("/openEdit")
    public String openEdit(Integer id, Model model) {
        SysMbzc sysMbzc = mbzcService.getMbzcById(id);
        model.addAttribute("mbzc",sysMbzc);
        return "/mbzc/mbzc_edit";
    }

    /**
     * 更新
     * @param sysMbzc
     * @param model
     * @return
     */
    @RequestMapping("/edit")
    public String edit(SysMbzc sysMbzc, HttpServletRequest request, Model model) {
        mbzcService.edit(sysMbzc);
        return getMbzcList(1, 10, request, model);
    }

    /**
     * 删除
     * @param id
     * @param model
     * @return
     */
    @RequestMapping("/delete")
    public String delete(Integer id, HttpServletRequest request, Model model) {
        mbzcService.delete(id);
        return getMbzcList(1, 10, request, model);
    }


}
